import { Controller, Get, Query, Req } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { JwtNeed } from '@/common/decorator'
import { WebListPageWheelRecordDto } from './dto/wheel-record.dto'
import { WheelRecordService } from './wheel-record.service'

@ApiTags('官网/二期/抽奖记录')
@Controller('web/wheel_record')
export class WebWheelRecordController {
  constructor(private readonly wheelRecordService: WheelRecordService) {}

  /**
   * 获取用户抽奖记录
   */
  @Get()
  @JwtNeed()
  page(@Req() req: Request, @Query() query: WebListPageWheelRecordDto) {
    const { pageNo, pageSize } = query
    return this.wheelRecordService.findPage({
      pageNo,
      pageSize,
      where: { userUid: req.user.uid },
      select: {
        wheelRecordId: true,
        userUid: true,
        wheelPrize: {
          wheelPrizeId: true,
          prizeName: true,
          prizeImage: true,
          prizeDescription: true,
        },

        createdAt: true,
        updatedAt: true,
      },
      relations: ['wheelPrize'],
    })
  }
}
